package ooday04;

import ooday04.Chick;
import ooday04.Dog;
import ooday04.Fish;

public class Test {
    public static <instenceof> void main(String[] args) {

        Master master=new Master();
        Dog dog=new Dog("小黑", 3, "黑色");
        Chick chick=new Chick("小坤", 29, "黑色");
        Fish fish=new Fish("金", 2, "黄金");
        master.feed(dog);
        master.feed(fish);
        master.feed(chick);



       /* Animal[] animals = new Animal[7];
        animals[0] = new Dog("小黑", 3, "黑色");
        animals[1] = new Dog("小白", 1, "白色");
        animals[2] = new Dog("大奔", 7, "黄色");
        animals[3] = new Chick("小坤", 29, "黑色");
        animals[4] = new Chick("小鸡", 3, "黄色");
        animals[5] = new Fish("花花", 1, "银色");
        animals[6] = new Fish("金", 2, "黄金");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i]instanceof Dog){
                Dog dog=(Dog) animals[i];
                dog.lookHome();
               // dog.swim();
            }
            if (animals[i] instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.layEggs();
                System.out.println(chick instanceof Animal);
            }

            if (animals[i] instanceof Swim){
                Swim s=(Swim) animals[i];
                s.swim();
            }
            if (animals[i] instanceof Fish){
                Fish fish=(Fish) animals[i];
                fish.swim();
            }


        }

        */
        Animal o = new Dog("小黑",2,"黑"); //向上造型
        Dog d = (Dog)o;   //引用o的对象，就是Doo类型
        Swim s = (Swim)o; //引用o的对象，实现了Swim接口
        Fish f = (Fish)o; //运行时会发生ClassCastException类型转换

        System.out.println(o instanceof Dog);  //true
        System.out.println(o instanceof Swim); //true
        System.out.println(o instanceof Fish); //false

    }
}
